package experimentUI;

import javax.swing.*;
import java.awt.*;

public class absolutePositionFrame extends JFrame {
    public absolutePositionFrame(String text){
        this.setTitle(text);
        this.setBackground(Color.white);
        this.setResizable(false);
        this.setLayout(null);
        this.setVisible(true);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }
    public absolutePositionFrame(){
        this.setBackground(Color.white);
        this.setResizable(false);
        this.setLayout(null);
        this.setVisible(true);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }
    public void BackgroundImage(String ImageName) {
        Container container=this.getContentPane();
        // 限定加载图片路径，相对路径
        ImageIcon icon= new ImageIcon("src/" + ImageName);
        final JLabel labelBackground = new JLabel();
        labelBackground.setIcon(icon);
        // 设置label的大小
        labelBackground.setBounds(0,0, icon.getIconWidth(), icon.getIconHeight());
        //设置窗口大小
        this.setBounds(0,0, icon.getIconWidth(), icon.getIconHeight()+40);
        // 将背景图片标签放入面板的最底层
        this.getLayeredPane().add(labelBackground, Integer.valueOf(Integer.MIN_VALUE));
        // 将容器转换为面板设置为透明
        JPanel panel = (JPanel)container;
        panel.setOpaque(false);
    }
}
